package top.whysu.edevice.controller.manage;

import org.springframework.stereotype.Controller;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import top.whysu.edevice.dto.generate.RequestDTO;
import top.whysu.edevice.dto.generate.ResponseDTO;
import top.whysu.edevice.dto.monitor.MonitorAddressRequestDTO;
import top.whysu.edevice.dto.monitor.MonitorAddressResponseDTO;
import top.whysu.edevice.service.manage.MonitorService;
import top.whysu.edevice.utils.ResponseUtil;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.Map;

/**
 * 视频监控
 */
@Controller
@RequestMapping("/monitor")
public class MonitorController {

    @Resource
    private MonitorService monitorService;

    /**
     * 监控页面
     */
    @RequestMapping("/monitor")
    public String monitor(Map<String, Object> map, BigDecimal deviceId) {
        map.put("deviceId", deviceId);
        return "manage/demo-monitor";
    }

    /**
     * 获取视频监控地址
     */
    @PostMapping("/getLiveAddress")
    @ResponseBody
    public ResponseDTO<MonitorAddressResponseDTO> addModifyDevice(@RequestBody @Validated RequestDTO<MonitorAddressRequestDTO> requestDTO) {
        MonitorAddressRequestDTO dto = requestDTO.getBody();
        return ResponseUtil.getSuccessResponse(requestDTO.getHeader(), monitorService.getLiveAddress(dto.getDeviceId()));
    }

}